layui.use(['form', 'layer', 'dropdown', 'upload'], function () {
    const form = layui.form,
        layer = parent.layer === undefined ? layui.layer : top.layer,
        $ = layui.jquery,
        upload = layui.upload,
        dropdown = layui.dropdown;

    //左侧菜单点击事件，其中 docDemoMenu1 对应的是菜单结构上的 id 指
    dropdown.on('click(docDemoMenu1)', function (options) {
        var othis = $(this); //当前菜单列表的 DOM 对象
        console.log(options); //菜单列表的 lay-options 中的参数
        switch (options.id) {
            case 1:
                window.location.href = "tool01.html";
                break;
            case 2:
                window.location.href = "tool02.html";
                break;
            case 3:
                window.location.href = "tool03.html";
                break;
            case 4:
                window.location.href = "tool04.html";
                break;
            case 5:
                window.location.href = "tool05.html";
                break;
        }
    });

    //多图片上传
    let coverUrl = "";
    upload.render({
        elem: '#test2'
        , url: host + '/a03/umsmember/uploadImage'
        , method: 'post'  //可选项。HTTP类型，默认post
        , field: 'multipartFile'
        , multiple: true
        , number: 5
        , before: function (obj) {
            //预读本地文件示例，不支持ie8
            obj.preview(function (index, file, result) {
                $('#demo2').append('<img src="' + result + '" alt="' + file.name + '" class="layui-upload-img thumbImg" style="margin-left: 2px">')
            });
        }
        , done: function (res) {
            //上传完毕
            //如果上传失败
            if (res.code !== 200) {
                return layer.msg('上传失败');
            } else {
                //上传成功
                coverUrl += res.data + ",";
            }
        }
    });

    //点击反馈记录
    $(".feedback").click(function () {
        let index = layui.layer.open({
            title: "反馈记录",
            type: 2,
            maxmin: false, //开启最大化最小化按钮
            // area: ["700px", "500px"],
            content: "tool05ByList.html",
            // shadeClose: true,
            success: function (layero, index) {

            }
        });
        layui.layer.full(index);
        window.sessionStorage.setItem("index", index);
        //改变窗口大小时，重置弹窗的宽高，防止超出可视区域（如F12调出debug的操作）
        $(window).on("resize", function () {
            layui.layer.full(window.sessionStorage.getItem("index"));
        });
    })

    form.on("submit(submit)", function (data) {
        console.log(data.field) //当前容器的全部表单字段，名值对形式：{name: value}

        var reqData = {
            content: data.field.content,
            doctorId: $.cookie("doctorId"),
            pic: coverUrl,
            yjId: 9
        };
        $.ajax({
            url: serverApi + "/doctorpropose/findO1Add" + "?" + formatParams(reqData),
            type: "POST",
            contentType: "application/x-www-form-urlencoded",
            success: function (result) {
                if (result.code === 200) {
                    layer.alert("建议已提交到系统");
                    location.reload();
                } else {
                    layer.msg('请求失败', {icon: 7, anim: 6});
                }
            }
        });

        return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
    });
});
